package com.ylbh.modules.comment.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.comment.dto.EvaluateClassDTO;
import com.ylbh.common.pojo.comment.dto.EvaluateClassListDTO;
import com.ylbh.common.pojo.comment.dto.ShoppingCommentReplyDTO;
import com.ylbh.common.pojo.comment.dto.ShoppingGoodsCommentDTO;
import com.ylbh.common.pojo.comment.vo.CommentReplyListVO;
import com.ylbh.common.pojo.comment.vo.CommentVO;
import com.ylbh.common.pojo.comment.vo.EvaluateClassListVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.comment.service.CommentService;
import com.ylbh.modules.sys.controller.AbstractController;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * 商品评论
 *
 * @author mgh
 * @date 2019-04-22 15:25:57
 */
@RestController
@RequestMapping("good/comment")
public class CommentController extends AbstractController {
    @Autowired
    private CommentService commentService;

    @ApiOperation("根据商品id添加采集评论")
    @SysLog("根据商品id添加采集评论")
    @RequestMapping("addCommentByGoodId/{goodsId}")
    @RequiresPermissions("order:shoppingBusinessOrder:getOrderByIdOrPayNo")
    public CommonResult getOrderByIdOrPayNo(@RequestBody List<ShoppingGoodsCommentDTO> shoppingGoodsCommentList, @PathVariable Integer goodsId){
        commentService.addCommentByGoodId(shoppingGoodsCommentList,goodsId);
        return Ref.ok();
    }

    @ApiOperation("商城评论列表")
    @GetMapping("queryCommentList")
    @RequiresPermissions("good:comment:queryCommentList")
    public CommonResult<PageUtils> queryCommentList(EvaluateClassListDTO pageDTO) {
        PageUtils page = commentService.queryCommentList(pageDTO);
        return Ref.ok(page);
    }

    @ApiOperation("评论审核")
    @PostMapping("modifyAuditStatusById/{statusType}")
    @RequiresPermissions("good:comment:modifyAuditStatusById")
    public CommonResult modifyAuditStatusById(@RequestBody Long[] ids, @PathVariable Integer statusType) {
        commentService.modifyAuditStatusById(Arrays.asList(ids), statusType);
        return Ref.ok();
    }

    @ApiOperation("回复审核")
    @PostMapping("modifyAuditReplyById/{statusType}")
    @RequiresPermissions("good:comment:modifyAuditStatusById")
    public CommonResult modifyAuditReplyById(@RequestBody Long[] ids, @PathVariable Integer statusType) {
        commentService.modifyAuditReplyById(Arrays.asList(ids), statusType);
        return Ref.ok();
    }

    @ApiOperation("删除评论")
    @PostMapping("removeCommentById")
    @RequiresPermissions("good:comment:removeCommentById")
    public CommonResult removeCommentById(@RequestBody Long[] commentIds) {
        commentService.removeCommentById(Arrays.asList(commentIds));
        return Ref.ok();
    }

    @ApiOperation("评论回复列表")
    @GetMapping("getCommentReplyListById/{commentId}")
    public CommonResult<CommentReplyListVO> getCommentReplyListById(@PathVariable String commentId) {
        CommentReplyListVO list = commentService.getCommentReplyListById(commentId);
        return Ref.ok(list);
    }

    @SysLog("回复评论提交")
    @ApiOperation("回复评论提交")
    @PostMapping("addCommentReply")
    public CommonResult addCommentReply(@RequestBody ShoppingCommentReplyDTO dto) {
        commentService.addCommentReply(dto);
        return Ref.ok();
    }

    @ApiOperation("评价标签列表")
    @GetMapping("queryEvaluateClassList")
    @RequiresPermissions("good:comment:queryEvaluateClassList")
    public CommonResult<PageUtils> queryEvaluateClassList(EvaluateClassListDTO dto) {
        PageUtils list = commentService.queryEvaluateClassList(dto);
        return Ref.ok(list);
    }

    @ApiOperation("获取标签详情")
    @GetMapping("getEvaluateClassDetailsById/{evaluateId}")
    @RequiresPermissions("good:comment:getEvaluateClassDetailsById")
    public CommonResult<EvaluateClassListVO> getEvaluateClassDetailsById(@PathVariable Integer evaluateId) {
        EvaluateClassListVO vo = commentService.getEvaluateClassDetailsById(evaluateId);
        return Ref.ok(vo);
    }

    @SysLog("修改评价标签")
    @ApiOperation("修改评价标签")
    @PostMapping("modifyEvaluateClassById")
    @RequiresPermissions("good:comment:modifyEvaluateClassById")
    public CommonResult modifyEvaluateClassById(@RequestBody EvaluateClassDTO dto) {
        commentService.modifyEvaluateClassById(dto);
        return Ref.ok();
    }

    @SysLog("新增评价标签")
    @ApiOperation("新增评价标签")
    @PostMapping("addEvaluateClass")
    @RequiresPermissions("good:comment:addEvaluateClass")
    public CommonResult addEvaluateClass(@RequestBody EvaluateClassDTO dto) {
        commentService.addEvaluateClass(dto);
        return Ref.ok();
    }

    @SysLog("删除评价标签")
    @ApiOperation("删除评价标签")
    @PostMapping("removeEvaluateClassById")
    @RequiresPermissions("good:comment:removeEvaluateClassById")
    public CommonResult removeEvaluateClassById(@RequestBody Integer commentIds) {
        commentService.removeEvaluateClassById(commentIds);
        return Ref.ok();
    }

    @ApiOperation("根据id来采集评论接口")
    @PostMapping("getGoodsComments/{id}/{numberOfBars}/{dataPage}")
    public CommonResult getGoodsComments(@PathVariable String id, @PathVariable Integer numberOfBars, @PathVariable Integer dataPage) {
        List<ShoppingGoodsCommentDTO> list = commentService.getGoodsComments(id, numberOfBars, dataPage);
        return Ref.ok(list);
    }

    @ApiOperation("根据goodsCollectionId来采集评论")
    @GetMapping("getGoodsComments/{goodsCollectionId}")
    public CommonResult getGoodsComments(@PathVariable String goodsCollectionId) {
        List<ShoppingGoodsCommentDTO> list = commentService.getGoodsCommentsById(goodsCollectionId);
        return Ref.ok(list);
    }

    @SysLog("添加商品评论")
    @ApiOperation("添加商品评论")
    @RequestMapping("addTimingComment/{goodsId}")
    @RequiresPermissions("order:shoppingBusinessOrder:getOrderByIdOrPayNo")
    public CommonResult addTimingComment(@RequestBody List<ShoppingGoodsCommentDTO> shoppingGoodsCommentList, @PathVariable Integer goodsId) {
        if (shoppingGoodsCommentList.size() > 0 && null != goodsId) {
            commentService.addTimingComment(shoppingGoodsCommentList, goodsId);
            return Ref.ok();
        } else {
            return Ref.error("没有采集到任何数据！");
        }
    }
    @SysLog("添加商品评论")
    @ApiOperation("添加商品评论")
    @RequestMapping("insertComment/{goodsId}")
    @RequiresPermissions("order:shoppingBusinessOrder:getOrderByIdOrPayNo")
    public CommonResult insertComment(@RequestBody List<ShoppingGoodsCommentDTO> shoppingGoodsCommentList, @PathVariable Integer goodsId) {
        if (shoppingGoodsCommentList.size() > 0 && null != goodsId) {
            commentService.insertComment(shoppingGoodsCommentList, goodsId);
            return Ref.ok();
        } else {
            return Ref.error("没有任何插入的数据！");
        }
    }
}
